package com.yiboshi.rehrs;

import cn.hutool.core.io.FileUtil;

import java.nio.charset.Charset;

public class HexToStringConverter {
    public static void main(String[] args) {
        String string = FileUtil.readString("C:\\Users\\472464220\\Desktop\\xiaofeixia\\美味\\login_v15.js", Charset.defaultCharset());
        String originalCode = string;
        String decodedCode = convertHexToChars(originalCode);
        System.out.println(decodedCode);
    }

    public static String convertHexToChars(String input) {
        StringBuilder result = new StringBuilder();
        int i = 0;
        while (i < input.length()) {
            if (input.startsWith("\\x", i)) {
                // 提取十六进制字符
                String hex = input.substring(i + 2, i + 4);
                // 将十六进制字符转换为十进制整数
                int decimal = Integer.parseInt(hex, 16);
                // 将十进制整数转换为字符
                result.append((char) decimal);
                i += 4;
            } else {
                result.append(input.charAt(i));
                i++;
            }
        }
        return result.toString();
    }
}